/// <reference path="../_References.ts"/>

class Input
{
    constructor()
    {
        document.onkeypress = this.getInput;
        document.onkeydown = this.getInput;
    }

    public getInput = (e) =>
    {
        var evtobj = window.event ? event : e; //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
        var unicode = evtobj.charCode ? evtobj.charCode : evtobj.keyCode;
        var keyPressed = String.fromCharCode(unicode);

        switch (keyPressed)
        {
            case "8": case "w": case "&":
                Game.direction = Game.DIRECTION.UP;
                break;
            case "2": case "s": case "(":
                Game.direction = Game.DIRECTION.DOWN;
                break;
            case "6": case "d": case "'":
                Game.direction = Game.DIRECTION.RIGHT;
                break;
            case "4": case "a": case "%":
                Game.direction = Game.DIRECTION.LEFT;
                break;
            case "f":
                Game.fps.enabled = !Game.fps.enabled;
        }
    };
}